<?php
class pollAction extends security_normal {
	
	function action(){
		$pollcategory=new model_Pollcategory();
		$pollcategory->setSubsection('WHERE isvisible=0 AND pollcategory_id='.$_POST['pollid']);
		$PollCategoryRS=$pollcategory->doSelectOne();
		if(!$PollCategoryRS){
			MessageBox('错误信息',MICE_URL,'对不起,您查看的投票不存在或已经被删除');
			exit;
		}//echo $PollCategoryRS->getTimes();exit();
		if($_COOKIE["pollip".$_POST['pollid']]){
			MessageBox('对不起,您已经投过票了',MICE_URL.'index.php/Pollresults/'.$_POST['pollid']);
			exit;
		}
		if($PollCategoryRS->getChecks()>0 and $PollCategoryRS->getChecks()<sizeof($_POST['poll'])){
			MessageBox('投票失败',MICE_URL.'index.php/Pollresults/'.$_POST['pollid'],'您最多可以同时选中'.$PollCategoryRS->getChecks().'项');
			exit;
		}
		setcookie("pollip".$_POST['pollid'],GetRealIp(),time()+$PollCategoryRS->getTimes());

		global $conn;
		if(sizeof($_POST['poll'])){
			if(is_array($_POST['poll'])){
				foreach($_POST['poll'] as $pid){
					$poll=new model_Poll();
					$poll->setSubsection('WHERE poll_id='.$pid);
					$results=$poll->doSelectOne();
					$poll->setNum($results->getNum()+1);
					$poll->doUpdate();
				}
			}else{
				$poll=new model_Poll();
				$poll->setSubsection('WHERE poll_id='.$_POST['poll']);
				$results=$poll->doSelectOne();
				$poll->setNum($results->getNum()+1);
				$poll->doUpdate();
			}
			$pollcategory->setNum($PollCategoryRS->getNum()+sizeof($_POST['poll']));//总票数
			$pollcategory->doUpdate();
			MessageBox('投票成功',MICE_URL.'index.php/Pollresults/'.$_POST['pollid']);
			exit;
		}else{
			MessageBox('投票失败',MICE_URL.'index.php/Pollresults/'.$_POST['pollid']);
			exit;
		}
	}	
}
?>